<link rel="stylesheet" href="__STATIC__/addon/file/Huploadify.css" />
<script src="__STATIC__/addon/file/jquery.Huploadify.js"></script>

<input type="hidden" name="{$addons_data['name']}" id="{$addons_data['name']}" value="{$addons_data['value']}"/>
<div class="upload-img-box{$addons_data['name']} clearfix">
    {notempty name="$info[$addons_data['name']]"}
        {assign name="img_ids_list" value="$info[$addons_data['name']]|str2arr" /}
        {volist name="img_ids_list" id='vo'}
            <div class="upload-pre-item" style="float:left; margin: 10px;">
                <div style="cursor:pointer; color:red;" class="pic_del"  onclick="picDel{$addons_data.name}(this, {$vo})" >
                    <img src="__STATIC__/addon/file/uploadify-cancel.png" />
                </div>
                <a target="_blank" href="{$vo|default=''|get_picture_url=$addons_data.addons_model}">
                    <img style="max-width:{$addons_config['maxwidth']};" src="{$vo|default=''|get_picture_url=$addons_data.addons_model}"/>
                </a>
            </div>
        {/volist}
    {/notempty}
</div>
<div id="upload_pictures_{$addons_data['name']}"></div>

<script type="text/javascript">

    var maxwidth = "{$addons_config['maxwidth']}";
    var height = "{$addons_config['height']}";

    $("#upload_pictures_{$addons_data['name']}").Huploadify({
        auto: true,
        height          : 30,
        fileObjName     : "file",
        buttonText      : "{$addons_config['button_text']}",
        uploader        : "{$addons_config['upload_url']}",
        width         : 120,
        removeTimeout	  : 1,
        fileSizeLimit:"{$addons_config['max_size']}",
        fileTypeExts	  : "{$addons_config['allow_postfix']}",
        onUploadComplete : uploadPicture{$addons_data.name}
    });

    function uploadPicture{$addons_data.name}(file, data){
        var data = $.parseJSON(data);//上传返回数据
        var addons_name = "{$addons_data.name}";

        var img_ids = $("#" + addons_name).val();//插件值

        var add_id = data.id;

        if(img_ids){
            img_ids = img_ids.replace('0,', '');
            var lastChar = img_ids.charAt(img_ids.length - 1);
            if(lastChar != ','){
                add_id = img_ids + ',' + add_id;
            }
        }
        $("#" + addons_name).val(add_id);

        //var src = '/upload/picture/' + data.path;
        var src ='__STATIC__/upload/picture/' + data.path;
        var src =src.replace(/\/static/g, '');
        $(".upload-img-box" + addons_name).prepend('<div class="upload-pre-item" style="float:left; margin: 10px;"> <div style="cursor:pointer; color:red;" class="pic_del"  onclick="picDel{$addons_data.name}(this,'+data.id+')" ><img src="__STATIC__/addon/file/uploadify-cancel.png" /></div> <a target="_blank" href="' + src + '"> <img style="max-width: ' + maxwidth + ';height: ' + height + ';" src="' + src + '"/></a></div>');
    }

    function picDel{$addons_data.name}(obj, pic_id)
    {

        var addons_name = "{$addons_data.name}";
        var img_ids = $("#" + addons_name).val();
        if(img_ids.indexOf(",") > 0)
        {
            img_ids.indexOf(pic_id) == 0 ? img_ids = img_ids.replace(pic_id + ',', '') : img_ids = img_ids.replace(',' + pic_id, '');
            $("#" + addons_name).val(img_ids);
        }else{
            $("#" + addons_name).val('');
        }
        $(obj).parent().remove();
    }
</script>